package com.qdlc.p2p.biz.task;

import java.util.List;

import com.qdlc.p2p.biz.tpp.model.SinaAuditMemberInfos;
import com.qdlc.p2p.dal.dto.Borrow;
import com.qdlc.p2p.dal.dto.BorrowRepayment;
import com.qdlc.p2p.dal.dto.EnjoyUser;
import com.qdlc.p2p.dal.dto.TppTradeLog;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.BondModel;
import com.qdlc.p2p.dal.model.BorrowModel;
import com.qdlc.p2p.dal.model.TppModel;

public class ConcurrentUtil {

    /**
     * 投标
     * @param model
     * @param borrow
     * @throws Exception
     */
    
    public static void tender(BorrowModel model, Borrow borrow) {
        ValueEvent event = new ValueEvent();     
        event.setOperate("tender");
        event.setBorrowModel(model);
        event.setBorrow(borrow);
        event.setResultFlag(model.getTenderResultFlg());
        JobQueue.getTenderInstance().offer(event);
    }
        
    
    /**
     * 自动投标
     * @param model
     * @throws Exception
     */
    public static void autoTender(BorrowModel model) throws Exception {
        ValueEvent event = new ValueEvent();
        event.setOperate("autoTender");
        event.setBorrowModel(model);
        JobQueue.getTenderInstance().offer(event);
    }
    
    
   /**
    * 自动投标本地处理
    * @param model
    * @throws Exception
    * @param
    */
    public static void doAutoTender(BorrowModel model,String resultFlag){
    	 ValueEvent event = new ValueEvent();
         event.setOperate("doAutoTender");
         event.setBorrowModel(model);
         event.setResultFlag(resultFlag);
         JobQueue.getTenderInstance().offer(event);
    }
    
    /**
     * 自动投标新浪处理
     * @param money
     * @param totalAccountYes
     * @param borrow
     * @param user
     * @param resultFlag
     * @throws Exception
     */
    public static void tppAutoTender(double money,double autoTenderMaxAcount,Borrow borrow,User user,String resultFlag) throws Exception {
        ValueEvent event = new ValueEvent();
        event.setOperate("tppAutoTender");
        event.setBorrow(borrow);
        event.setUser(user);
        event.setMoney(money);
        event.setAutoTenderMaxAcount(autoTenderMaxAcount);
        event.setLastflag(resultFlag);
        JobQueue.getTenderInstance().offer(event);
    }
    
    /**
     * 满标复审
     * @param model
     * @throws Exception
     */
    public static void autoVerifyFull(BorrowModel model) throws Exception {
        ValueEvent event = new ValueEvent();
        event.setOperate("autoVerifyFull");
        event.setBorrowModel(model);
        JobQueue.getVerifyBorrowInstance().offer(event);
    }   

    /**
     * 复审通过
     * @param model
     * @throws Exception
     */
    public static void autoVerifyFullSuccess(BorrowModel model) throws Exception {
        ValueEvent event = new ValueEvent();
        event.setOperate("autoVerifyFullSuccess");
        event.setBorrowModel(model);
        JobQueue.getVerifyBorrowInstance().offer(event);
    }

    /**
     * 复审不通过
     * @param model
     * @throws Exception
     */
    public static void autoVerifyFullFail(BorrowModel model) throws Exception {
        ValueEvent event = new ValueEvent();
        event.setOperate("autoVerifyFullFail");
        event.setBorrowModel(model);
        JobQueue.getVerifyBorrowInstance().offer(event);
    }

    /**
     * 还款
     * @param borrowRepayment
     */
    public static void repay(BorrowRepayment borrowRepayment) {
        ValueEvent event = new ValueEvent();
        event.setOperate("repay");
        event.setBorrowRepayment(borrowRepayment);
        JobQueue.getBorrowInstance().offer(event);
    }
    /**
     * 撤标
     * @param model
     */
    public static void autoCancel(Borrow borrow) {
        ValueEvent event = new ValueEvent();
        event.setOperate("autoCancel");
        event.setBorrow(borrow);
        JobQueue.getBorrowInstance().offer(event);
    }
    
    /**
     * 提前还款
     * @param borrowRepayment
     */
    public static void doPriorRepay(BorrowRepayment borrowRepayment) {
        ValueEvent event = new ValueEvent();
        event.setOperate("doPriorRepay");
        event.setBorrowRepayment(borrowRepayment);
        JobQueue.getBorrowInstance().offer(event);
    }
    /**
     * 后台逾期垫付
     * @param borrowRepayment
     */
    public static void overdue(BorrowRepayment borrowRepayment) {
        ValueEvent event = new ValueEvent();
        event.setOperate("overdue");
        event.setBorrowRepayment(borrowRepayment);
        JobQueue.getBorrowInstance().offer(event);
    }
    /**
     * 前台逾期垫付
     * @param borrowRepayment
     */
    public static void overduePayment(BorrowRepayment borrowRepayment) {
        ValueEvent event = new ValueEvent();
        event.setOperate("overduePayment");
        event.setBorrowRepayment(borrowRepayment);
        JobQueue.getBorrowInstance().offer(event);
    }

    /**
     * 发标回调
     * @param user
     * @param ips
     */
    public static void doAddBorrow(BorrowModel bm){
        ValueEvent event = new ValueEvent();
        event.setOperate("doAddBorrow");
        event.setBorrowModel(bm);
        JobQueue.getBorrowInstance().offer(event);
        
    }
    /**
     * 登记担保方
     * @param bm
     */
    public static void doIpsRegisterGuarantor(BorrowModel bm, String resultFlag){
        ValueEvent event = new ValueEvent();
        event.setOperate("doIpsRegisterGuarantor");
        event.setBorrowModel(bm);
        event.setResultFlag(resultFlag);
        JobQueue.getUserInstance().offer(event);
    }
    
    /**
     * 投标回调
     * @param bm
     */
    public static void doAddTender(BorrowModel bm,String resultFlag){
        ValueEvent event = new ValueEvent();
        event.setOperate("doAddTender");
        event.setBorrowModel(bm);
        event.setResultFlag(resultFlag);
        JobQueue.getTenderInstance().offer(event);
        
    }
    
    /**
     * 代偿回调
     * @param borrowRepayment
     */
    public static void doCompensateSuccess(BorrowRepayment borrowRepayment) {
        ValueEvent event = new ValueEvent();
        event.setOperate("doCompensateSuccess");
        event.setBorrowRepayment(borrowRepayment);
        JobQueue.getBorrowInstance().offer(event);
    }
    
    /**
     * 投标
     * @param model
     * @param borrow
     * @throws Exception
     */
    
    public static void bondTender(BondModel model)throws Exception{
        ValueEvent event = new ValueEvent();
        event.setOperate("bondTender");
        event.setBondModel(model);
        JobQueue.getBondInstance().offer(event);

    }    
    

    /**
     * 第三方开户
     * @param userId
     * @param tppUserId
     * @param tppUserCustId
     * @param flag
     */
    public static void tppRegisger(long userId,String tppUserId,String tppUserCustId,String flag,String cardId,String realName){
    	 ValueEvent event = new ValueEvent();
    	 event.setUserId(userId);
    	 event.setTppUserId(tppUserId);
    	 event.setTppUserCustId(tppUserCustId);
    	 event.setResultFlag(flag);
    	 event.setCardId(cardId);
    	 event.setRealName(realName);
    	 event.setOperate("tppRegisger");
    	 JobQueue.getUserInstance().offer(event);
    }
    
    /**
     * 企业开户成功
     * @param memberInfos
     * @param flag
     */
    public static void tppAuditMemberInfosSuccess(
    		SinaAuditMemberInfos memberInfos, String flag) {
    	 ValueEvent event = new ValueEvent();
    	 event.setAuditOrderNo(memberInfos.getAudit_order_no());
    	 event.setInnerOrderNo(memberInfos.getInnerOrderNo());
    	 event.setAuditStatus(memberInfos.getAuditStatus());
    	 event.setAuditMessage(memberInfos.getAuditMessage());
    	 event.setOperate("tppAuditMemberInfosSuccess");
    	 JobQueue.getUserInstance().offer(event);
    }
    
    /**
     * 企业开户失败
     * @param memberInfos
     * @param flag
     */
    public static void tppAuditMemberInfosFail(
    		SinaAuditMemberInfos memberInfos, String flag) {
    	 ValueEvent event = new ValueEvent();
    	 event.setAuditOrderNo(memberInfos.getAudit_order_no());
    	 event.setInnerOrderNo(memberInfos.getInnerOrderNo());
    	 event.setAuditStatus(memberInfos.getAuditStatus());
    	 event.setAuditMessage(memberInfos.getAuditMessage());
    	 event.setOperate("tppAuditMemberInfosFail");
    	 JobQueue.getUserInstance().offer(event);
    }

    /**
     * 第三方代收交易
     * @param taskList
     * @param
     */
    public static void tppCollectTrade(TppTradeLog tppTradeLog) {
    	ValueEvent event = new ValueEvent();
    	event.setTppTradeLog(tppTradeLog);
    	event.setOperate("tppCollectTrade");
    	JobQueue.getTppTradeInstance().offer(event);
    }
    
    /**
     * 第三方放款业务处理
     * 
     * @param taskList 执行队列
     *//*
    public static void tppLoan(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppLoan");
    	JobQueue.getTppInvestInstance().offer(event);
    }
    
    *//**
     * 第三方还款业务处理
     * 
     * @param repayment 本期借款人还款计划
     *//*
    public static void tppBorrowRepayment(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppBorrowRepayment");
    	JobQueue.getTppInvestInstance().offer(event);
    }
    
    *//**
     * 第三方借款标撤销业务处理
     * 
     * @param taskList 执行队列
     *//*
    public static void tppBorrowCancle(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppBorrowCancle");
    	JobQueue.getTppInvestInstance().offer(event);
    }
    
    *//**
     * 第三方借款标复审失败业务处理
     * 
     * @param taskList 执行队列
     *//*
    public static void tppBorrowFail(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppBorrowFail");
    	JobQueue.getTppInvestInstance().offer(event);
    }
    
    *//**
     * 第三方商户给用户转账业务处理
     * 
     * @param taskList
     *//*
    public static void tppTransfer(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppTransfer");
    	JobQueue.getTppInvestInstance().offer(event);
    }*/
    
    public static void tppPayTrade(TppTradeLog tppTradeLog) {
    	ValueEvent event = new ValueEvent();
    	event.setTppTradeLog(tppTradeLog);
    	event.setOperate("tppPayTrade");
    	JobQueue.getTppTradeInstance().offer(event);
    }
    
    /**
     * 第三方队列处理
     * 
     * @param taskList
     */
    public static void tppTask(List<TppModel> taskList) {
    	ValueEvent event = new ValueEvent();
    	event.setTaskList(taskList);
    	event.setOperate("tppTask");
    	JobQueue.getTppInvestInstance().offer(event);
    }

    /**
     * 趣享发放奖品预处理
     */
    public static void giveEnjoyGoods(EnjoyUser enjoyUser){
        ValueEvent event = new ValueEvent();
        event.setEnjoyUser(enjoyUser);
        JobQueue.getEnjoyGoodsInstance().offer(event);
    }

    /**
     * 购买电影票队列处理
     * @param resultFlag
     *
     * @param taskList
     */
    public static void buyMovieTickets(long userId, double actualPayMoney,long id,int moviePages, String resultFlag) {
        ValueEvent event = new ValueEvent();
        event.setOperate("buyMovieTickets");
        event.setUserId(userId);
        event.setMoney(actualPayMoney);
        event.setMoviePages(moviePages);
        event.setId(id);
        event.setResultFlag(resultFlag);
        JobQueue.getBuyMovieTicketsInstance().offer(event);
    }


	public static void tppDispatch(TppModel tppModel) {
		ValueEvent event = new ValueEvent();
        event.setOperate("tppDispatch");
        event.setTppModel(tppModel);
        JobQueue.getTppDispatchInstance().offer(event);
	}

}
